<template>
	<om-addpage :busCode="busCode" :menuName="menuName" @formSubmit="formSubmit" :showHistoryBtn="false">
		<om-autoform ref="autoform" :initConfigData="initConfigData" :initValue="initValue"></om-autoform>
	</om-addpage>
</template>

<script>
	import {
		errorModal,
		ignoreHtml,
		getUrl,
		confirmModal,
		ptFloat,
		minusF
	} from '@/static/js/common.js';
	import {
		buildFormData,
		formValidation,
		tranferToEditors,
		changeEditor,
		setSubmitSubValue,
		configSelectData,
		hasValue,
		formShowLoading,
		getFormFields,
		formModelLoad,
		getWorkCacheKey
	} from '@/static/js/formUtil.js';
	import urlUtil from '@/static/js/urlUtil.js';
	import { mapState } from 'pinia';
	import {useLoginUserStore} from '@/stores/login-user.js';
	export default {
		provide() {
			return {
				formPage: this
			};
		},
		data() {
			return buildFormData({
				processesList:[],
				productCache:"product-process-productCode-cache",
				prevPage:"",
				initConfigData:[{
					title:"新增产品工序",
					key:"title0",
					editors:[
						{
							checkedit:null,
							editReadonly:null,
							isfull:null,
							link:"../../public/pageSearch/pageSearch",
							linkParam:{
								cachename:"product-process-productCode-cache",
								initload:true,
								namefield:"projectCode",
								notefield:"projectName",
								extrafield:"projectMnemonic",
								other:"{}",
								searchfield:"q",
								url:"productShow/getPage"
							},
							max:"",
							min:"",
							nameField:"projectCode",
							prompt:"请选择",
							required:false,
							title:"产品编码",
							type:"linkbox",
							valueField:"projectId",
						},
						{
							checkedit:null,
							editReadonly:null,
							isfull:null,
							max:"",
							min:"",
							nameField:"projectName",
							required:false,
							title:"产品名称",
							type:"labelbox",
							valueField:"projectName",
						},
						{
							checkedit:null,
							editReadonly:null,
							isfull:null,
							max:"",
							min:"",
							nameField:"projectStd",
							required:false,
							title:"规格型号",
							type:"labelbox",
							valueField:"projectStd",
						},
						{
							checkedit:null,
							editReadonly:null,
							isfull:null,
							max:"",
							min:"",
							nameField:"projectUnit",
							required:false,
							title:"单位",
							type:"labelbox",
							valueField:"projectUnit",
						},
						{
							checkedit:null,
							editReadonly:null,
							isfull:null,
							max:"",
							min:"",
							nameField:"processesSort",
							required:false,
							title:"工序号码",
							type:"numberbox",
							valueField:"processesSort",
						},
						{
							checkedit:null,
							editReadonly:null,
							isfull:null,
							data:[],
							editReadonly:true,
							nameField:"processesName",
							required:false,
							title:"工序名称",
							prompt:"请选择",
							type:"selectbox",
							valueField:"processesName",
						}
					]
				}]
			})
		},
		computed: {
			...mapState(useLoginUserStore, ['userName', 'userId'])
		},
		methods:{
			formSubmit(){
				let _that = this
				let arr = []
				let obj  = {}
				 arr.push(_that.formdata,obj) 
				_that.formdata.dataStr = JSON.stringify(arr)
				_that.om.formSave("productProcessShow/doAddShow",_that.formdata,_that,function(id){
					_that.prevPage.$vm.addProductProcess = true
				})
				uni.navigateBack()
			},
			initLoad(options){
				let _that = this
				_that.om.request(
					"tsysdict/getCombobox",
					{
						code:"38559"
					}
				).then(res=>{
					changeEditor("title0","processesName","data",configSelectData(res,"id","dicname"),this.initConfigData)
				})
			}
		},
		onLoad(options) {
			let _that = this
			_that.initLoad(options)
		},
		onShow() {
			let _that = this
			let pages = getCurrentPages()
			_that.prevPage = pages[pages.length - 2]
			if(_that.$refs.autoform){
				uni.getStorage({
					key:_that.productCache,
					success:(res)=>{
						let d = res.data
						let formdata = _that.$refs.autoform.formdata
						formdata.projectId = d.id
						formdata.projectName = d.projectName
						formdata.projectCode = d.projectCode
						formdata.projectStd = d.projectStd
						formdata.projectUnit = d.projectUnit
						uni.removeStorage({
							key:_that.productCache
						})
					}
				})
			}
		}
	}
</script>

<style>
</style>